#ifndef _ICAR_FLAT_MSG_H
#define _ICAR_FLAT_MSG_H

#if defined(__cplusplus)
extern "C" {
#endif

#include "icar_msg.h"
#include "icar_end_param.h"

#define AREA_ATTRI_TIME				0x0001
#define AREA_ATTRI_RATELIMIT		0x0002
#define AREA_ATTRI_INTODRIVER		0x0004
#define AREA_ATTRI_INTOFLAT			0x0008
#define AREA_ATTRI_OUTTODRIVER		0x0010
#define AREA_ATTRI_OUTTOFLAT		0x0020
#define AREA_ATTRI_LATITUDE			0x0040	/* 南纬 */
#define AREA_ATTRI_LONGITUDE		0x0080	/* 西经 */
#define AREA_ATTRI_INCOM_MODULE		0x4000  /* 进区域关闭通信模块 */
#define AREA_ATTRI_INGNSS_LOCAL		0x8000	/* 进区域采集GNSS详细定位数据 */


#define ROUTE_ATTR_TIME				0x01
#define ROUTE_ATTR_RATELIMIT		0x02
#define ROUTE_ATTR_LATITUDE			0x04	/* 南纬 */
#define ROUTE_ATTR_LONGITUDE		0x08	/* 西经 */
/* 平台通用应答 */
struct flatRes {
	uint16_t sequence;	/* 对应的终端消息的流水号 */
	uint16_t endId;		/* 对应的终端消息的ID*/
	uint8_t result;		/* 结果： 0:成功／确认 1: 失败 2:消息有误 3:不支持 */
};

/* 下发终端升级包 */
struct flatUpdate {
	uint8_t type;			/* 升级类型 0:终端 12:道路运输证IC卡读卡器 52: 北斗星定位模块 */
	uint8_t manufacturer[5];	/* 制造商编号 */
	uint8_t verLen;			/* 版本号长度 */
	char	*version;		/* 版本号 */
	uint32_t upLen;			/* 升级数据包长度 */
	void *data;				/* 升级数据包 */
};

/* 提问下发 */
struct flatAskIssue {
	uint8_t type;		/* 标志 */
	uint8_t askLen;		/* 问题内容长度 */
	char *	ask;		/* 问题文本，经GBK编码，长度为N */
	uint8_t answerId;	/* 答案ID */
	uint16_t answerLen;	/* 答案内容长度 */
	char	*answer;	/* 答案内容 */
};

/* 信息点播信息项组成数据格式 */
struct infoOption {
	uint8_t type;	/* 若终端已有同类型的信息项，则被覆盖 */
	int iov_len;	/* 信息名称字段字节长度 */
	void *iov_base;	/* 信息名称 经GBK编码处理 */
};

/* 信息点播菜单设置 */
struct flatInfoMenu {
	uint8_t type;	/* 设置类型: 0: 删除终端全部信息项 1:更新菜单 2:追加菜单 3:修改菜单 */
	uint8_t total;	/* 信息项总数 */
	struct infoOption iov[256];	/* 信息点播信息项组成数据 */
};

/* 电话本联系人项数据格式 */
struct contacts {
	uint8_t mark;	/* 标志 1: 呼入 2: 呼出 3: 呼入／呼出 */
	uint8_t nlen;
	char 	number[32];
	uint8_t clen;
	char	contac[256];
};

struct flatPhone {
	uint8_t type;
	uint8_t total;
	struct contacts co[256];
};

struct areaOption {
	uint32_t id;
	uint16_t property;
	uint32_t latitude;
	uint32_t longitude;
	uint32_t radius;
	uint8_t  stime[6];
	uint8_t  etime[6];
	uint16_t speed;
	uint8_t  otime;
};

struct flatSetCycle {
	uint8_t property;
	uint8_t total;
	struct areaOption ap[256];
};

struct flatDelCycle {
	uint8_t total;
	uint32_t id[128];
};

struct recArea {
	uint32_t id;
	uint16_t property;
	uint32_t lulatitude;
	uint32_t lulongitude;
	uint32_t rdlatitude;
	uint32_t rdlongitude;
	uint8_t  stime[6];
	uint8_t  etime[6];
	uint16_t speed;
	uint8_t  otime;
};

struct flatSetRec {
	uint8_t property;
	uint8_t total;
	struct recArea ra[256];
};

struct flatDelRec {
	uint8_t total;
	uint32_t id[128];
};

struct point {
	uint32_t latitude;
	uint32_t longitude;
};

struct flatSetPoly {
	uint32_t id;
	uint16_t property;
	uint8_t stime[6];
	uint8_t etime[6];
	uint16_t speed;
	uint8_t otime;
	uint16_t total;
	struct point **po;
};

struct flatDelPoly {
	uint8_t total;
	uint32_t id[128];
};

/* 设置路线拐点项数据格式 */
struct flatInflexion {
	uint32_t flexId;
	uint32_t routeId;
	uint32_t latitude;
	uint32_t longitude;
	uint8_t routeWidth;
	uint8_t routeAttr;
	uint16_t longThre;
	uint16_t lackThre;
	uint16_t speed;
	uint8_t otime;
};

struct flatSetRoute {
	uint32_t id;
	uint16_t property;
	uint8_t  stime[6];
	uint8_t etime[6];
	uint16_t total;
	struct flatInflexion **fi;
};

struct flatDelRoute {
	uint8_t total;
	uint32_t id[128];
};

struct flatMediaRes {
	uint32_t id;
	uint8_t total;
	uint16_t list[256];
};

/* 摄像头立即拍摄命令 */
struct flatFilm {
	uint8_t channelId;	/* 通道ID 	*/
	uint16_t cmd;		/* 拍摄命令 */
	uint16_t interval;	/* 拍照间隔／录像时间 */
	uint8_t mark;		/* 保存标志	*/
	uint8_t resolution;	/* 分辨率 */
	uint8_t quality;	/* 图像／视频质量 */
	uint8_t bright;		/* 亮度   */
	uint8_t contrast;	/* 对比度 */
	uint8_t saturate;	/* 饱和度 */
	uint8_t chroma;		/* 色度		*/
};

/* 存储多媒体数据检索 */
struct flatMediaCheck {
	uint8_t type;		/* 多媒体类型 0:图像 1:音频 2:视频 */
	uint8_t channelId;	/* 0 表示检索该媒体类型的所有通道 */
	uint8_t opCode;		/* 事件项编码 0:平台下发指令 1:定时动作 2:抢劫报警触发 3:碰撞侧翻报警触发 其他保留 */
	uint8_t stime[6];	/* 起始时间 */
	uint8_t etime[6];	/* 结束时间 */
};

/* 存储多媒体数据上传命令 */
struct flatMediagUpload {
	uint8_t type;		/* 多媒体类型 0:图像 1:音频 2:视频 */
	uint8_t channelId;	/* 通道ID */
	uint8_t opCode;		/* 事件项编码 0:平台下发指令 1:定时动作 2:抢劫报警触发 3:碰撞侧翻报警触发 其他保留 */
	uint8_t stime[6];	/* 起始时间 YY-MM-DD-hh-mm-ss */
	uint8_t etime[6];	/* 结束时间	YY-MM-DD-hh-mm-ss */
	uint8_t mark;		/* 0:保留 1:删除 */
};

/* 录音开始命令 */
struct flatRecordCmd {
	uint8_t cmd;	/* 录音命令 0:停止录音 0x01:开始录音 */
	uint16_t time;	/* 录音时间 单位为秒(s)，0表示一直录音 */ 
	uint8_t mark;	/* 保存标志 0:实时上传 1:保存 */
	uint8_t sample;	/* 音频采样率 0: 8K; 1: 11K; 2: 23K; 3: 32K; 其他保留 */
};

/* 单条存储多媒体数据检索上传命令 */
struct flatRetrieveUp {
	uint32_t mediaId;	/* 多媒体ID */
	uint8_t mark;		/* 删除标志 0:保留 1:删除 */
};

/* 平台RSA公钥 */
struct flatRSA {
	uint32_t e;		/* 平台RSA 公钥{e,n}中的e */
	uint8_t n[128];	/* RSA 公钥{e,n}中的n */
};

struct icar_iovec *flat_genricRes(int rsa, const char *number, struct flatRes *res);

struct icar_iovec *flat_supplement_req(int rsa, const char *number, struct supplement_req *);

struct icar_iovec *flat_reg_response(int rsa, const char *number, struct regiser_res *);

struct icar_iovec *flat_get_end_param(const char *number);

struct icar_iovec *flat_get_spec_param(int rsa, const char *number, uint32_t *list, size_t size);

struct icar_iovec *flat_get_end_property(const char *number);

struct icar_iovec *flat_end_update(int rsa, const char *number, struct flatUpdate *);

struct icar_iovec *flat_get_location(const char *number);
struct icar_iovec *flat_temp_local_ctrl(int rsa, const char *number, uint16_t, uint32_t);
struct icar_iovec *flat_confirm_alarm(int rsa, const char *number, uint16_t sequence, uint32_t flag);

struct icar_iovec *flat_textInfo_issue(int rsa, const char *number, uint8_t flag, char *info);

struct icar_iovec *flat_ask_issue(int rsa, const char *number, struct flatAskIssue *);

struct icar_iovec *flat_infoMenu_set(int rsa, const char *number, struct flatInfoMenu *);

struct icar_iovec *flat_infoServ(int rsa, const char *number, uint8_t type, char *info, uint16_t len);

struct icar_iovec *flat_phoneCallback(int rsa, const char *number, uint8_t mark, char *phone);

struct icar_iovec *flat_setPhoneBook(int rsa, const char *number, struct flatPhone *book);

struct icar_iovec *flat_vehiCtrl(int rsa, const char *number, uint8_t flag);

struct icar_iovec *flat_setCycle(int rsa, const char *number, struct flatSetCycle *set);

struct icar_iovec *flat_delCycle(int rsa, const char *number, struct flatDelCycle *del);

struct icar_iovec *flat_setRectangle(int rsa, const char *number, struct flatSetRec *rec);
struct icar_iovec *flat_delRectangle(int rsa, const char *number, struct flatDelRec *rec);


struct icar_iovec *flat_setPolygon(int rsa, const char *number, struct flatSetPoly *poly);
struct icar_iovec *flat_delPolygon(int rsa, const char *number, struct flatDelPoly *poly);

struct icar_iovec *flat_setRoutine(int rsa, const char *number, struct flatSetRoute *route);
struct icar_iovec *flat_delRoutine(int rsa, const char *number, struct flatDelRoute *route);


struct icar_iovec *flat_repDriverInfo(int rsa, const char *number);
struct icar_iovec *flat_multiResponse(int rsa, const char *number, struct flatMediaRes *);

struct icar_iovec *flat_cameraFilm(int rsa, const char *number, struct flatFilm *film);

/* 设置终端参数 */
struct icar_iovec *set_end_param(int rsa, const char *number, struct param_list *list);


/* 存储多媒体数据检索 */
struct icar_iovec *flat_mediaCheck(int rsa, const char *number, struct flatMediaCheck *check);

/* 存储多媒体数据上传命令 */
struct icar_iovec *flat_mediaUpload(int rsa, const char *number, struct flatMediagUpload *upload);

/* 录音开始命令 */
struct icar_iovec *flat_recordCmd(int rsa, const char *number, struct flatRecordCmd *cmd);

/* 单条存储多媒体数据检索上传命令 */
struct icar_iovec *flat_retrieveUpload(int rsa, const char *number, struct flatRetrieveUp *up);

/* 平台RSA公钥 */
struct icar_iovec *flat_rsaEncry(int rsa, const char *number, struct flatRSA *r);

#if defined(__cplusplus)
}
#endif


#endif
